﻿#region zh-CHS 2006 - 2007 DemoSoft 团队 | en 2006 - 2007 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the G.O.S.E(Game Online Server Engine) for .NET.
//
//                 2006-2007 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using Demo_G.O.S.E.ServerEngine.Item;
#endregion

namespace Demo_G.O.S.E.ServerEngine.Treasure
{
    /// <summary>
    /// 
    /// </summary>
    public class BaseLoot
    {
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private ConstructorInfo m_Constructor = null;
        #endregion

        #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <param name="fProbability"></param>
        public BaseLoot( Type type, float fProbability )
        {
            ConstructorInfo[] l_ConstructorInfoArray = type.GetConstructors();
            foreach ( ConstructorInfo l_ConstructorInfo in l_ConstructorInfoArray )
            {
                ParameterInfo[] l_ParameterInfoArray = l_ConstructorInfo.GetParameters();
                if ( l_ParameterInfoArray.Length == 0 )
                {
                    m_Constructor = l_ConstructorInfo;
                    break;
                }
            }

            m_fProbability = fProbability;

            if ( m_Constructor == null )
                Debug.WriteLine( "Loot.Loot(...) - m_Constructor == null error({0})!", type.ToString() );
        }
        #endregion

        #region zh-CHS 共有属性 | en Public Properties
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private float m_fProbability = 0.0f;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public float Probability
        {
            get { return m_fProbability; }
        }
        #endregion

        #region zh-CHS 共有方法 | en Public Methods
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public virtual BaseItem Instance()
        {
            if ( m_Constructor == null )
            {
                Debug.WriteLine( "Loot.Instance(...) - m_Constructor == null error!" );
                return null;
            }

            return m_Constructor.Invoke( null ) as BaseItem;
        }
        #endregion
    }
}
#endregion